
#include "ali_rmq.h"
#include <string.h>
#include <iostream>

PushListener::PushListener(void){_Consumer = NULL;}

DLL_EXPORT_C_DECL void* WINAPI CreateConsumer(char *cid, char *access_key, char *secret)
{
    //pushConsumer 创建和工作需要的参数，必须输入
    ONSFactoryProperty factoryInfo;
    factoryInfo.setFactoryProperty(ONSFactoryProperty::ConsumerId, cid);//您在 MQ 控制台创建的 consumer ID
    factoryInfo.setFactoryProperty(ONSFactoryProperty::PublishTopics, "");//您在 MQ 控制台创建的 msg topic
    factoryInfo.setFactoryProperty(ONSFactoryProperty::AccessKey, access_key);//阿里云身份验证，在阿里云服务器管理控制台创建
    factoryInfo.setFactoryProperty(ONSFactoryProperty::SecretKey,  secret);//阿里云身份验证，在阿里云服务器管理控制台创建
    //factoryInfo.setFactoryProperty(ONSFactoryProperty::ONSAddr, "http://onsaddr-internal.aliyun.com:8080/rocketmq/nsaddr4client-internal");
      // 集群订阅方式 (默认)
//    factoryInfo.setFactoryProperty(ONSFactoryProperty:: MessageModel, ONSFactoryProperty::CLUSTERING);
      // 广播订阅方式
      // factoryInfo.setFactoryProperty(ONSFactoryProperty:: MessageModel, ONSFactoryProperty::BROADCASTING);
    //create pushConsumer
    PushConsumer* pushConsumer = ONSFactory::getInstance()->createPushConsumer(factoryInfo);
    return pushConsumer;
}

DLL_EXPORT_C_DECL void* WINAPI CreateListener()
{
    //指定 pushConsumer 订阅的消息 topic 和 tag，注册消息回调函数
//    ConsumeMsgListener  msglistener;
    return new PushListener();
 }

DLL_EXPORT_C_DECL void WINAPI Shutdown(PushConsumer *consumer)
{
    consumer->shutdown();
}


DLL_EXPORT_C_DECL void WINAPI Subscribe(PushConsumer *consumer, PushListener *listener, char *topic, char *tag)
{
    consumer->subscribe(topic, tag, listener);
    //start pushConsumer
    consumer->start();
}

DLL_EXPORT_C_DECL void WINAPI SetOnConsumer(PushListener* spi, void* func){spi->_Consumer = func;}

// ********************************* OrderConsume ********************************************

OrderListener::OrderListener(void){_Consumer = NULL;}

DLL_EXPORT_C_DECL void* WINAPI CreateOrderConsumer(char *cid, char *access_key, char *secret)
{
    //pushConsumer 创建和工作需要的参数，必须输入
    ONSFactoryProperty factoryInfo;
    factoryInfo.setFactoryProperty(ONSFactoryProperty::ConsumerId, cid);//您在 MQ 控制台创建的 consumer ID
    factoryInfo.setFactoryProperty(ONSFactoryProperty::PublishTopics, "");//您在 MQ 控制台创建的 msg topic
    factoryInfo.setFactoryProperty(ONSFactoryProperty::AccessKey, access_key);//阿里云身份验证，在阿里云服务器管理控制台创建
    factoryInfo.setFactoryProperty(ONSFactoryProperty::SecretKey,  secret);//阿里云身份验证，在阿里云服务器管理控制台创建
    //factoryInfo.setFactoryProperty(ONSFactoryProperty::ONSAddr, "http://onsaddr-internal.aliyun.com:8080/rocketmq/nsaddr4client-internal");
      // 集群订阅方式 (默认)
//    factoryInfo.setFactoryProperty(ONSFactoryProperty:: MessageModel, ONSFactoryProperty::CLUSTERING);
      // 广播订阅方式
      // factoryInfo.setFactoryProperty(ONSFactoryProperty:: MessageModel, ONSFactoryProperty::BROADCASTING);
    //create pushConsumer
    OrderConsumer* pushConsumer = ONSFactory::getInstance()->createOrderConsumer(factoryInfo);
    return pushConsumer;
}

DLL_EXPORT_C_DECL void* WINAPI CreateOrderListener()
{
    //指定 pushConsumer 订阅的消息 topic 和 tag，注册消息回调函数
//    ConsumeMsgListener  msglistener;
    return new OrderListener();
 }

DLL_EXPORT_C_DECL void WINAPI ShutdownOrder(OrderConsumer *consumer)
{
    consumer->shutdown();
}


DLL_EXPORT_C_DECL void WINAPI SubscribeOrder(OrderConsumer *consumer, OrderListener *listener, char *topic, char *tag)
{
    consumer->subscribe(topic, tag, listener);
    //start pushConsumer
    consumer->start();
}

DLL_EXPORT_C_DECL void WINAPI SetOnOrderConsumer(OrderListener* spi, void* func){spi->_Consumer = func;}

